#!/bin/bash
# Fedora Utils for software, codec installs and system tweaks for Fedora.
# Copyright (C) 2011  Satyajit sahoo
#
# License: GNU General Public License 3 <http://www.gnu.org/licenses/gpl-3.0.html>
# Author: IT-vabakad <here-comes-email>
# Site: Project Page <http://code.google.com/p/ubuntu-utils/>
#
# Ubuntu Utils lets you install multimedia codecs, flash, java, microsoft fonts,
# install many additional softwares not available in Fedora repos,
# useful tweaks such as autologin, add user to sudoers etc.
# turn off unnecessary daemons to improve boot time,
# fix problems and cleanup your system,
# view your system information and much more with just few clicks.
#
# This script modifies system files and adds software from various repositories and other sources which are not under its control.
#
# This script benefits both for codes and ideas from
# AutoPlus by dangermouse <http://www.dnmouse.org/autoten/>
# easyLife by dulinux <http://easylifeproject.org>
# FedoraUtils  by Satyajit Sahoo <http://fedorautils.sorceforge.net>
#
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# http://www.gnu.org/licenses/gpl-3.0.html
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# No Warranty or guarantee of suitability exists for this software
# Use at your own risk. The author is not responsible if your system breaks.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

# Declare Variables
PROGRAM="Ubuntu Utils"
VERSION="0.0.1-dev"
USER="$(logname)"
HOMEDIR=`awk -F: -v v="$(logname)" '{if ($1==v) print $6}' /etc/passwd`
REBOOTREQUIRED="NO"
FORCE="NO"
FORCEDISTRO="NO"
ERRORS="0"
ARG="$1"
# Settings
AUTOUPDATE="OFF"						# If you want to turn off autoupdate, change "ON" to "OFF"
WORKINGDIR="/tmp/ubuntuutils"				# If Downloads folder exists, the content is synced here
KEEPBACKUP="YES"					# If you don't want to backup previous configurations, change "YES" to "NO"
KEEPDOWNLOADS="YES"					# If you don't intend to save downloads, change "YES" to "NO"
DOWNLOADSDIR="$HOMEDIR/UbuntuUtils"			# This is where you'll find the Downloads
KEEPLOG="OFF"						# If you want to enable logging, change "NO" to "YES"
LOGFILE="/var/log/ubuntuutils.log"			# Outputs will be redirected to this file if logging is enabled
LOCKFILE='/var/run/ubuntuutils.pid'			# This is the lockfile used to prevent multiple instances
# Set Colors
BOLD="\033[1;10m"
RED="\033[0;31m"
REDBOLD="\033[1;31m"
GREEN="\033[0;32m"
GREENBOLD="\033[1;32m"
YELLOW="\033[0;33m"
YELLOWBOLD="\033[1;33m"
BLUE="\033[0;34m"
BLUEBOLD="\033[1;34m"
ENDCOLOR="\033[0m"

# Define Functions

function CleanTemp()
{
if [ -d "$WORKINGDIR" ]; then
rm -rf "$WORKINGDIR"
fi
if [ -d "$DOWNLOADSDIR" ]; then
chown -R "$USER" "$DOWNLOADSDIR"
# Delete Downloads directory if it is empty
rmdir --ignore-fail-on-non-empty $DOWNLOADSDIR
echo -e $GREEN"Temporary Directory Cleaned"$ENDCOLOR
fi
if [ "$REBOOTREQUIRED" = "YES" ]; then
	echo -e $YELLOW"You might need to Reboot to apply all changes"$ENDCOLOR
fi
# Delete lockfile
if [ $(whoami) = "root" ]; then
	rm -f "$LOCKFILE"
	if [ $? != 0 ]; then
	   exit 1;
	fi
fi
}

function Terminate()
{
CleanTemp
echo -e $REDBOLD"Program Terminated."$ENDCOLOR
if [ "$KEEPLOG" = "YES" ]; then
	zenity --warning --text="Program Terminated. Check log at "$LOGFILE". Click Ok to Exit."
else
	zenity --warning --text="Program Terminated. Click Ok to Exit."
fi
exit 1;
}

function Complete()
{
if [ ! "$ERRORS" = "0" ]; then
echo -e $RED"$PROGRAM encountered $ERRORS errors. You might want to run $PROGRAM again with logging enabled and report if there are any bugs."$ENDCOLOR
	if [ "$FORCEDISTRO" = "YES" ]; then
	echo -e $RED"$PROGRAM is designed for Fedora and not guarranteed to work in other distros, even other Fedora Remixes."$ENDCOLOR
	if [ "$INTERNET" = "NO" ]; then
	echo -e $RED"Additionally it is recommended to run $PROGRAM with a working internet connection and check it if works."$ENDCOLOR
	fi
	if [ "$USINGLATEST" = "NO" ]; then
	echo -e $RED"It is highly recommended to update $PROGRAM first."$ENDCOLOR
	fi
	fi
fi
CleanTemp
echo -e $BLUEBOLD"Completed."$ENDCOLOR
zenity --info --text="Completed. Click Ok to Exit."
exit 0;
}

function Success()
{
echo -e $GREENBOLD"Successfully Completed."$ENDCOLOR
}

function Failure()
{
echo -e $REDBOLD"Completed, but with Errors!"$ENDCOLOR
ERRORS=$((ERRORS+1))
}

function Done()
{
echo -e $BLUE"Done"$ENDCOLOR
}

function GetFile()
{
if [ ! -f "$WORKINGDIR/$file" ] || [ "$FORCE" = "YES" ]; then
echo -e $BLUE"Downloading $file..."$ENDCOLOR
curl -L -O -# "$get"
else
echo -e $BLUE"$file already present, skipping download"$ENDCOLOR
fi
}

function SaveFile()
{
if [ "$KEEPDOWNLOADS" = "YES" ]; then
mv -f "$file" "$DOWNLOADSDIR"
fi
}

function InstallFile()
{
dpkg -i "$file"
}

function EnableLog()
{
# Enable logging
if [ "$KEEPLOG" = "YES" ]; then
	# Unset Colors
	unset BOLD
	unset RED
	unset REDBOLD
	unset GREEN
	unset GREENBOLD
	unset YELLOW
	unset YELLOWBOLD
	unset BLUE
	unset BLUEBOLD
	unset ENDCOLOR
	# Rotate old logfile
	if [ -e "$LOGFILE" ]; then
		mv "$LOGFILE" ""$LOGFILE"-$(date +"%Y%m%d%H%M%S")"
	fi
	# Create logfile
	touch "$LOGFILE"
	echo "[$(date)]" | tee -a "$LOGFILE"
	echo "" | tee -a "$LOGFILE"
	echo "$PROGRAM - $VERSION" | tee -a "$LOGFILE"
	echo $(cat /etc/issue) | tee -a "$LOGFILE"
	echo $(uname -irs) | tee -a "$LOGFILE"
	echo "" | tee -a "$LOGFILE"
	echo "[Variables]" | tee -a "$LOGFILE"
	echo "" | tee -a "$LOGFILE"
	echo "Home Directory is $HOMEDIR" | tee -a "$LOGFILE"
	echo "Work Directory is $WORKINGDIR" | tee -a "$LOGFILE"
	echo "Keep Backup? $KEEPBACKUP" | tee -a "$LOGFILE"
	echo "Keep Downloads? $KEEPDOWNLOADS" | tee -a "$LOGFILE"
	echo "Downloads directory is $DOWNLOADSDIR" | tee -a "$LOGFILE"
	echo "Force Downloads? $FORCE" | tee -a "$LOGFILE"
	echo "Logfile is "$LOGFILE"" | tee -a "$LOGFILE"
	echo "" >> "$LOGFILE"
	echo "[Outputs]" >> "$LOGFILE"
	echo "" >> "$LOGFILE"
	exec &>> "$LOGFILE"
fi
}

function CheckArgs()
{
if [ "$ARG" = "--log" ]; then
KEEPLOG="YES"
elif [ "$ARG" = "--force" ]; then
FORCE="YES"
elif [ "$ARG" = "--distro" ]; then
FORCEDISTRO="YES"
elif [ "$ARG" = "--noupd" ]; then
AUTOUPDATE="NO"
elif [ "$ARG" = "--nobak" ]; then
KEEPBACKUP="NO"
elif [ "$ARG" = "--debug" ]; then
	if [ -e "$LOGFILE" ]; then
		cat "$LOGFILE"
	else
		echo -e "No logfile exists. Try running Fedora Utils with logging enabled. Use --help for more details"
	fi
exit
elif [ "$ARG" = "--set-sudo" ]; then
AddSudoer
exit
elif [ "$ARG" = "--set-autologin" ]; then
AutoLogin
exit
elif [ "$ARG" = "--set-tidycache" ]; then
TidyCache
exit
elif [ "$ARG" = "--set-touchpad" ]; then
TouchPad
exit
elif [ "$ARG" = "--set-colors" ]; then
ColorTerm
exit
elif [ "$ARG" = "--set-fortune" ]; then
FortuneTerm
exit
elif [ "$ARG" = "--set-selinux" ]; then
SELinuxConf
exit
elif [ "$ARG" = "--repo-rpmfusion" ]; then
RPMFusion
exit
elif [ "$ARG" = "--repo-google" ]; then
GoogleRepo
exit
elif [ "$ARG" = "--repo-adobe" ]; then
AdobeRepo
exit
elif [ "$ARG" = "--repo-chromium" ]; then
ChromiumRepo
elif [ "$ARG" = "--repo-skype" ]; then
SkypeRepo
elif [ "$ARG" = "--repo-add-all" ]; then
AddRepo
exit
elif [ "$ARG" = "--install-codecs" ]; then
InstallCodecs
exit
elif [ "$ARG" = "--install-dvdcodecs" ]; then
EnableDVD
exit
elif [ "$ARG" = "--install-flash" ]; then
InstallFlash
exit
elif [ "$ARG" = "--install-java" ]; then
InstallJava
exit
elif [ "$ARG" = "--install-wine" ]; then
InstallWine
exit
elif [ "$ARG" = "--install-gtalk" ]; then
GTalk
exit
elif [ "$ARG" = "--install-corefonts" ]; then
CoreFonts
exit
elif [ "$ARG" = "--install-jockey" ]; then
InstallJockey
exit
elif [ "$ARG" = "--install-chrome" ]; then
InstallGoogleChrome
exit
elif [ "$ARG" = "--install-picasa" ]; then
InstallPicasa
exit
elif [ "$ARG" = "--install-earth" ]; then
InstallGoogleEarth
exit
elif [ "$ARG" = "--install-jupiter" ]; then
InstallJupiter
exit
elif [ "$ARG" = "--install-handbrake" ]; then
InstallHandBrake
exit
elif [ "$ARG" = "--install-skype" ]; then
InstallSkype
exit
elif [ "$ARG" = "--install-winff" ]; then
InstallWinFF
exit
elif [ "$ARG" = "--install-jdk" ]; then
InstallJDK
exit
elif [ "$ARG" = "--install-unico" ]; then
InstallUnico
exit
elif [ "$ARG" = "--install-extension-gpaste" ]; then
GPaste
exit
elif [ "$ARG" = "--install-extension-mediaplayer" ]; then
MediaPlayer
exit
elif [ "$ARG" = "--install-extension-weather" ]; then
WeatherExtension
exit
elif [ "$ARG" = "--install-extension-monitor" ]; then
SysMonitor
exit
elif [ "$ARG" = "--install-extension-pidgin" ]; then
PidginShell
exit
elif [ "$ARG" = "--install-extension-statusmenu" ]; then
AltStatusMenu
exit
elif [ "$ARG" = "--install-extension-places" ]; then
PlacesMenu
exit
elif [ "$ARG" = "--install-extension-usertheme" ]; then
UserTheme
exit
elif [ "$ARG" = "--install-extension-navigator" ]; then
WindowsNavigator
exit
elif [ "$ARG" = "--install-extension-zeitgeist" ]; then
Zeitgeist
exit
elif [ "$ARG" = "--fix-fonts" ]; then
FixFonts
exit
elif [ "$ARG" = "--fix-theme" ]; then
FixTheme
exit
elif [ "$ARG" = "--fix-rpmdb" ]; then
FixRPMdb
exit
elif [ "$ARG" = "--fix-keyring" ]; then
FixKeyring
exit
elif [ "$ARG" = "--fix-picasa" ]; then
FixPicasa
exit
elif [ "$ARG" = "--fix-jockey" ]; then
FixJockey
exit
elif [ "$ARG" = "--fix-anaconda" ]; then
FixAnaconda
exit
elif [ "$ARG" = "--fix-mplayer" ]; then
FixMPlayer
exit
elif [ "$ARG" = "--fix-ntfsconfig" ]; then
FixNTFS
exit
elif [ "$ARG" = "--help" ]; then
ShowLicense
echo -e "Usage:\tfedorautils [arguement]\v\n\t--log\t\tstart with logging enabled\n\t--force\t\tforce redownload of files\n\t--distro\trun with unsupported distro\n\t--noupd\t\tstart with autoupdate disabled\n\t--nobak\t\tdo not keep backups\n\t--debug\t\tshow last logfile and exit\n\t--help\t\tshow this help message and exit\v\nRun with no arguements for the normal GUI. Use --help-all for all available options. Note that if you run $PROGRAM without root privilleges, it will try to accquire root previlleges first and all arguements will reset and won't work."
exit
elif [ "$ARG" = "--help-all" ]; then
echo -e "Usage:\tfedorautils [arguement]\v\n\t--set-sudo\t\tAdd Sudoer\n\t--set-autologin\t\tSetup AutoLogin\n\t--set-tidycache\t\tSetup TidyCache\n\t--set-touchpad\t\tEnable TouchPad Tap\n\t--set-colors\t\tAdd Colors to Terminal\n\t--set-fortune\t\tAdd Fortune to Terminal\n\t--set-selinux\t\tSet SELinux to Permissive\n\t--repo-rpmfusion\t\tAdd RPMFusion Repo\n\t--repo-google\t\tAdd Google Repo\n\t--repo-adobe\t\tAdd Adobe Repo\n\t--repo-chromium\t\tAdd Chromium Repo\n\t--repo-skype\t\tAdd Skype Repo\n\t--repo-add-all\t\tAdd All Repos\n\t--install-codecs\t\tInstall Multimedia Codecs\n\t--install-dvdcodecs\t\tEnable DVD Playback\n\t--install-flash\t\tInstall Adobe Flash\n\t--install-java\t\tInstall JRE\n\t--install-wine\t\tInstall Wine\n\t--install-gtalk\t\tInstall GTalk\n\t--install-corefonts\t\tInstall MS Core Fonts\n\t--install-jockey\t\tInstall Jockey\n\t--install-chrome\t\tInstall Google Chrome\n\t--install-picasa\t\tInstall Picasa\n\t--install-earth\t\tInstall Google Earth\n\t--install-jupiter\t\tInstall Jupiter\n\t--install-handbrake\t\tInstall HandBrake\n\t--install-skype\t\tInstall Skype\n\t--install-winff\t\tInstall WinFF\n\t--install-jdk\t\tInstall JDK\n\t--install-unico\t\tInstall Unico\n\t--install-extension-gpaste\t\tInstall GPaste Extension\n\t--install-extension-mediaplayer\t\tInstall Media Player Extension\n\t--install-extension-weather\t\tInstall Weather Extension\n\t--install-extension-monitor\t\tInstall System Monitor Extension\n\t--install-extension-pidgin\t\tInstall Pidgin Extension\n\t--install-extension-statusmenu\t\tInstall Alternative Status Menu\n\t--install-extension-places\t\tInstall Places Menu Extension\n\t--install-extension-usertheme\t\tInstall User Theme Extension\n\t--install-extension-navigator\t\tInstall Window Navigator Extension\n\t--install-extension-zeitgeist\t\tInstall Zeitgeist Extension\n\t--fix-fonts\t\tFix Font Smoothing\n\t--fix-theme\t\tFix Bad Theme\n\t--fix-rpmdb\t\tFix rpmdb\n\t--fix-keyring\t\tFix Gnome Keyring\n\t--fix-picasa\t\tFix Picasa\n\t--fix-jockey\t\tFix Jockey\n\t--fix-anaconda\t\tFix Anaconda\n\t--fix-mplayer\t\tFix MPlayer\n\t--fix-ntfsconfig\t\tFix NTFS config\v\nRun with no arguements for the normal GUI. Note that if you run $PROGRAM without root privilleges, it will try to accquire root previlleges first and all arguements will reset and won't work."
exit
elif [ ! "$ARG" = "" ]; then
echo -e "Invalid arguement $ARG. Try --help for list of arguements."
exit
fi
}

function ShowLicense()
{
echo -e $BOLD"$PROGRAM $VERSION Copyright (C) 2011 IT-vabakad"$ENDCOLOR
echo -e ""
echo -e "This program comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under the terms of GNU GPL V3 or Later."
echo -e ""
echo -e "You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>"
echo -e ""
}

function Update() #Fixme:Change url
{
echo -e $BLUEBOLD"Checking Update"$ENDCOLOR
curl -s http://sourceforge.net/api/file/index/project-id/504600/mtime/desc/limit/1/rss -o update.tmp
latest=$(grep "guid" update.tmp | sed -e 's/^[ \t]*//' | cut -c77-93)
vdir=$(grep "guid" update.tmp | sed -e 's/^[ \t]*//' | cut -c59-73)
current=fedorautils-$VERSION
rm -f update.tmp
if [ "$latest" = "$current" ]; then
	echo -e $GREEN"$PROGRAM is Up-to-date"$ENDCOLOR
elif [[ "$latest" < "$current" ]]; then
	echo -e $YELLOW"How come you are using a newer version than the latest?"$ENDCOLOR
else
	if [ "$AUTOUPDATE" = "ON" ]; then
		echo -e $BLUE"Update found. Downloading Update..."$ENDCOLOR
		curl -s http://master.dl.sourceforge.net/project/fedorautils/$vdir/$latest -o "$HOMEDIR/$latest"
		if [ -e "$HOMEDIR/$latest" ]; then
		chown "$USER" "$HOMEDIR/$latest"
		chmod a+x "$HOMEDIR/$latest"
		zenity --info --title="$PROGRAM Updated!" --text="An updated version of $PROGRAM has been automatically downloaded and saved to $HOMEDIR/$latest. Please use that script instead."
		Complete
		else
		echo -e $RED"Update failed!"$ENDCOLOR
		fi
	else
		echo -e $YELLOW"An update to $PROGRAM is available. It might contain new features and bug fixes. You are recommended to use the new version instead. Visit http://fedorautils.sf.net for changelog and details."$ENDCOLOR
	fi
fi
if [ ! "$latest" = "$current" ]; then
USINGLATEST="NO"
fi
}

function CheckLock()
{
if [ $(whoami) = "root" ]; then
	# Check for existing lockfile
	if [ -e "$LOCKFILE" ]; then
		if [ ! -r "$LOCKFILE" ]; then
		echo -e $RED"Cannot open lockfile!"$ENDCOLOR
		exit 1;
		fi
		PID=`cat "$LOCKFILE"`
		kill -0 "$PID" 2>/dev/null
		if [ $? == 0 ]; then
		echo -e $RED"Another instance of $PROGRAM is already running!"$ENDCOLOR
		exit 1;
		fi
		# Process that created lockfile is no longer running - delete lockfile
		rm -f "$LOCKFILE"
		if [ $? != 0 ]; then
		exit 1;
		fi
	fi
	# Create lockfile
	echo $$ >"$LOCKFILE"
	if [ $? != 0 ]; then
	   exit 1;
	fi
fi
}

function CheckReq()
{
echo -e $BLUEBOLD"Verifying minimum system requirements"$ENDCOLOR
# Check Distro
s=`cat /etc/issue | grep -i "Fedora"`
if [ -n "$s" ]; then
	echo -e $GREEN"Distro Verified"$ENDCOLOR
else
	if [ "$FORCEDISTRO" = "YES" ]; then
	echo -e $YELLOW"Unsupported distro, but will continue as instructed"$ENDCOLOR
	else
	echo -e $RED"Distro not supported"$ENDCOLOR
# 	Terminate #TODO: Add support for ubuntu
	fi
fi
if [ -e /etc/fedora-release ]; then
echo -e $GREEN"$(cat /etc/fedora-release) Detected"$ENDCOLOR
fver="$(cat /etc/fedora-release | cut -c16-17)"
else
echo -e $YELLOW"Could not detect version"$ENDCOLOR
fi
# Check Architecture
if [ $(uname -i) = "i386" ]; then
	echo -e $GREEN"Architecture Verified (32-bit)"$ENDCOLOR
elif [ $(uname -i) = "x86_64" ]; then
	echo -e $GREEN"Architecture Verified (64-bit)"$ENDCOLOR
else
	echo -e $RED"Architecture not supported"$ENDCOLOR
	Terminate
fi
# Check User
if [ "! $(whoami)" = "root" ]; then #Open script with normal user.
	echo -e $RED"Root access is needed to run $PROGRAM"$ENDCOLOR
	zenity --question --title="Root access needed!" --text="$PROGRAM needs root access to work. Are you sure to continue?" --ok-label "Yes" --cancel-label "No"
	if [ $? == 1 ]; then
		Terminate
	else
		AddSudoer
		echo -e $YELLOW"Attempting to run $PROGRAM with root previleges, all arguements will reset"$ENDCOLOR
		exec sudo $0 "$@"
		exit;
	fi
else
	echo -e $GREEN"Root Access Verified"$ENDCOLOR
	echo -e $GREEN"$USER Registered as Logged in User"$ENDCOLOR
fi
# Check Connection
i=`ping -c 1 www.google.com > "/dev/null" 2>&1` ;
if [ $? = 0 ]; then
	echo -e $GREEN"Internet Connection Verified"$ENDCOLOR
	Update
else
	echo -e $RED"No working internet connection found"$ENDCOLOR
	zenity --warning --text="No working internet connection found. $PROGRAM requires internet connection to work properly. You may encounter problems."
	INTERNET="NO"
fi
# Check Zenity
if [ -e /usr/bin/zenity ]; then
	echo -e $GREEN"Zenity Verified"$ENDCOLOR
else
	echo -e $RED"Zenity is needed for $PROGRAM to run properly. Installing zenity"$ENDCOLOR
	sudo yum -y install --nogpgcheck zenity
	if [ ! -e /usr/bin/zenity ]; then
		echo -e $RED"Installation of zenity failed"$ENDCOLOR
		Terminate
	fi
fi
# Check Curl
if [ -e /usr/bin/curl ]; then
	echo -e $GREEN"Curl Verified"$ENDCOLOR
else
	echo -e $RED"Curl is needed for $PROGRAM to run properly. Installing curl"$ENDCOLOR
	sudo yum -y install --nogpgcheck curl
	if [ ! -e /usr/bin/curl ]; then
		echo -e $RED"Installation of curl failed"$ENDCOLOR
		Terminate
	fi
fi
# Create Additional Directories
mkdir -p "$WORKINGDIR"
mkdir -p "$DOWNLOADSDIR"
rsync -r -u "$DOWNLOADSDIR/" "$WORKINGDIR"
if [ "$FORCE" = "YES" ]; then
echo -e $BLUE"Forced mode, will redownload files even if already downloaded"$ENDCOLOR
fi
cd "$WORKINGDIR"
echo -e $GREEN"Temporary Directory $(pwd) Created"$ENDCOLOR
}

function AddSudoer()
{
echo -e $BLUE"Checking sudo access"$ENDCOLOR
echo "$(sudo -l)" >> checksudo.tmp
r=`cat checksudo.tmp | grep "(ALL)"`
rm -f checksudo.tmp
if [ -n "$r" ]; then
	echo -e $GREEN"Sudo access exists"$ENDCOLOR
else
	zenity --question --title="Add you to sudoers list?" --text="Adding yourself to sudoers will enable you to perform operations as root. Do you want $PROGRAM to add $USER to the sudoers list? You will need to enter root password in the Terminal." --ok-label "Yes" --cancel-label "No"
	if [ ! $? == 1 ]; then
	su -c "echo '$USER ALL=(ALL) ALL' >> /etc/sudoers"
	#su -c "echo '$USER ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers"
	echo -e $GREEN"Done"$ENDCOLOR
	else
	echo -e "As you wish. I was just helping"
	Terminate
	fi
fi
}

function AutoLogin()
{
echo -e $BLUEBOLD"Enabling Autologin"$ENDCOLOR
s=`cat /etc/gdm/custom.conf | grep -i "AutomaticLoginEnable=True"`
if [ -n "$s" ]; then
echo -e $GREEN"Autologin already enabled"$ENDCOLOR
else
cat <<EOF | tee -a /etc/gdm/custom.conf
[daemon]
AutomaticLogin=$USER
AutomaticLoginEnable=True
EOF
fi
s=`cat /etc/gdm/custom.conf | grep -i "AutomaticLoginEnable=True"`
if [ -n "$s" ]; then
Success
else
Failure
fi
}

function YumConfig()
{
echo -e $BLUEBOLD"Setting up Yum to Keep Cache"$ENDCOLOR
s=`cat /etc/yum.conf | grep -i "keepcache=1"`
if [ -n "$s" ]; then
echo -e $GREEN"Yum already configured to keep package cache"$ENDCOLOR
else
	if [ "$KEEPBACKUP" = "YES" ]; then
	cp /etc/yum.conf /etc/yum.conf.bak
	fi
sed -i 's/keepcache=0/keepcache=1/g' /etc/yum.conf
fi
s=`cat /etc/yum.conf | grep -i "keepcache=1"`
if [ -n "$s" ]; then
Success
else
Failure
fi
}

function TidyCache()
{
echo -e $BLUEBOLD"Installing Tidy Cache plugin for Yum"$ENDCOLOR
if [ -f /usr/lib/yum-plugins/tidy-cache.py ]; then
echo -e $GREEN"Tidy Cache plugin for Yum is already installed"$ENDCOLOR
else
	file="tidy-cache-LATEST.tar.gz"
	get="http://www.hyperdrifter.com/software/files/tidy-cache-LATEST.tar.gz"
	GetFile
	tar xzf "$file"
	cp tidy-cache/tidy-cache.py /usr/lib/yum-plugins/
	cp tidy-cache/tidy-cache.conf /etc/yum/pluginconf.d/
	SaveFile
fi
if [ -f /usr/lib/yum-plugins/tidy-cache.py ]; then
Success
else
Failure
fi
}

function RPMFusion()
{
# Set up RPM Fusion
if [ -f /etc/yum.repos.d/rpmfusion-free.repo ]; then
echo -e $GREEN"RPM Fusion free repo already present"$ENDCOLOR
else
yum -y localinstall --nogpgcheck http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-stable.noarch.rpm
fi
if [ -f /etc/yum.repos.d/rpmfusion-nonfree.repo ]; then
echo -e $GREEN"RPM Fusion nonfree repo already present"$ENDCOLOR
else
yum -y localinstall --nogpgcheck http://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-stable.noarch.rpm
fi
}

function GoogleRepo()
{
# Add Google Repo
if [ -f /etc/yum.repos.d/google.repo ]; then
echo -e $GREEN"Google repo already present"$ENDCOLOR
else
curl -s https://dl-ssl.google.com/linux/linux_signing_key.pub -o linux_signing_key.pub
rpm --import linux_signing_key.pub
rm -f linux_signing_key.pub
cat <<EOF | tee /etc/yum.repos.d/google.repo
[Google] 
name=Google - $(uname -i)
baseurl=http://dl.google.com/linux/rpm/stable/$(uname -i)
enabled=1 
gpgcheck=1 
gpgkey=https://dl-ssl.google.com/linux/linux_signing_key.pub
EOF
fi
}

function AdobeRepo()
{
# Set up Adobe Repo
if [ $(uname -i) = "i386" ]; then
	if [ -f /etc/yum.repos.d/adobe-linux-i386.repo ]; then
	echo -e $GREEN"Adobe repo already present"$ENDCOLOR
	else
	yum -y localinstall --nogpgcheck http://linuxdownload.adobe.com/adobe-release/adobe-release-i386-1.0-1.noarch.rpm
	fi
fi
}

function ChromiumRepo()
{
# Add Chromium Repo
if [ -f /etc/yum.repos.d/fedora-chromium.repo ]; then
echo -e $GREEN"Chromium repo already present"$ENDCOLOR
else
cat <<EOF | tee /etc/yum.repos.d/fedora-chromium.repo
[fedora-chromium]
name=Chromium web browser and deps
baseurl=http://repos.fedorapeople.org/repos/spot/chromium/fedora-\$releasever/\$basearch/
enabled=1
gpgcheck=0

[fedora-chromium-source]
name=Chromium web browser and deps - Source
baseurl=http://repos.fedorapeople.org/repos/spot/chromium/fedora-\$releasever/SRPMS/
enabled=0
gpgcheck=0
EOF
fi
}

function SkypeRepo()
{
# Add Skype Repo
if [ -f /etc/yum.repos.d/skype.repo ]; then
echo -e $GREEN"Skype repo already present"$ENDCOLOR
else
cat <<EOF | tee /etc/yum.repos.d/skype.repo
[skype]
name=Skype Repository
baseurl=http://download.skype.com/linux/repos/fedora/updates/i586/
#gpgkey=http://www.skype.com/products/skype/linux/rpm-public-key.asc
enabled=1
gpgcheck=0
EOF
fi
}

function ParsidoraRepo()
{
if [ -f /etc/yum.repos.d/parsidora.repo ]; then
echo -e $GREEN"Parsidora repo already present"$ENDCOLOR
else
# Add Parsidora Repo
cat <<EOF | tee /etc/yum.repos.d/parsidora.repo
[parsidora] 
name=Parsidora 15 – \$basearch
baseurl=http://parsidora.sourceforge.net/releases/15/repos/parsidora/\$basearch
enabled=0
gpgcheck=0
EOF
fi
}

function AddRepo()
{
echo -e $BLUEBOLD"Adding Repos"$ENDCOLOR
if [ -f /etc/yum.repos.d/rpmfusion-free.repo ] && [ -f /etc/yum.repos.d/rpmfusion-nonfree.repo ] && [ -f /etc/yum.repos.d/google.repo ] && [ -f /etc/yum.repos.d/fedora-chromium.repo ] && [ -f /etc/yum.repos.d/skype.repo ]; then
echo -e $GREEN"Repos already added"$ENDCOLOR
else
RPMFusion
GoogleRepo
AdobeRepo
ChromiumRepo
SkypeRepo
fi
if [ -f /etc/yum.repos.d/rpmfusion-free.repo ] && [ -f /etc/yum.repos.d/rpmfusion-nonfree.repo ] && [ -f /etc/yum.repos.d/google.repo ] && [ -f /etc/yum.repos.d/fedora-chromium.repo ] && [ -f /etc/yum.repos.d/skype.repo ]; then
Success
else
Failure
fi
}

function TouchPad()
{
echo -e $BLUEBOLD"Enabling Touchpad Tap"$ENDCOLOR
if [ -f /etc/X11/xorg.conf.d/00-enable-taps.conf ]; then
echo -e $GREEN"Touchpad Tap already enabled"$ENDCOLOR
else
yum -y install --nogpgcheck xorg-x11-drv-synaptics
cat <<EOF | tee /etc/X11/xorg.conf.d/00-enable-taps.conf
Section "InputClass"
       Identifier "tap-by-default"
       MatchIsTouchpad "on"
       Option "TapButton1" "1"
EndSection
EOF
fi
if [ -f /etc/X11/xorg.conf.d/00-enable-taps.conf ]; then
Success
else
Failure
fi
}

function InstallCodecs()
{
echo -e $BLUEBOLD"Installing Multimedia Codecs"$ENDCOLOR
if [ -d /usr/share/doc/gstreamer-plugins-ugly* ]; then
echo -e $GREEN"GStreamer Plugins already installed"$ENDCOLOR
else
RPMFusion
yum -y install --nogpgcheck gnome-mplayer gstreamer-plugins-good gstreamer-plugins-bad gstreamer-plugins-bad-free gstreamer-plugins-bad-nonfree gstreamer-plugins-ugly gstreamer-ffmpeg faac faad2 libdca libmad libmatroska xvidcore
fi
# Install MPlayer Codecs if Architecture is 32-bit
if [ $(uname -i) = "i386" ]; then
	if [ -d /usr/local/lib/codecs ]; then
	echo -e $GREEN"MPlayer Codecs already installed"$ENDCOLOR
	else
	file="all-20110131.tar.bz2"
	get="http://www.mplayerhq.hu/MPlayer/releases/codecs/all-20110131.tar.bz2"
	GetFile
	tar -jxvf "$file"
	mkdir -p /usr/local/lib/codecs
	cp all-20110131/* /usr/local/lib/codecs
	ln -sf /usr/local/lib/codecs /usr/lib/codecs && ln -sf /usr/local/lib/codecs /usr/local/lib/win32 && ln -sf /usr/local/lib/codecs /usr/lib/win32
	SaveFile
	fi
else
	echo -e $YELLOW"Skipping installation of MPlayer Codecs as it is only supported in 32-bit architecture"$ENDCOLOR
fi
# Remove possible defective thumbnails
rm -rf "$HOMEDIR/.thumbnails/*"
if [ -d /usr/share/doc/gstreamer-plugins-ugly* ] && [ -d /usr/local/lib/codecs ]; then
Success
else
Failure
fi
}

function EnableDVD()
{
DVDCodecs
DVDCss
}

function DVDCodecs()
{
echo -e $BLUEBOLD"Installing DVD Codecs"$ENDCOLOR
if [ -d /usr/share/doc/libdvdread* ] && [ -d /usr/share/doc/libdvdnav* ] && [ -d /usr/share/doc/lsdvd* ]; then
echo -e $GREEN"DVD Codecs already installed"$ENDCOLOR
else
RPMFusion
yum -y install --nogpgcheck libdvdread libdvdnav lsdvd
fi
if [ -d /usr/share/doc/libdvdread* ] && [ -d /usr/share/doc/libdvdnav* ] && [ -d /usr/share/doc/lsdvd* ]; then
Success
else
Failure
fi
}

function DVDCss()
{
echo -e $BLUEBOLD"Installing libdvdcss"$ENDCOLOR
if [ -f /usr/lib/libdvdcss.so.2 ]; then
echo -e $GREEN"libdvdcss already installed"$ENDCOLOR
else
	if [ $(uname -i) = "i386" ]; then
	file="libdvdcss2-1.2.10-5.fc15.i686.rpm"
	get="http://dl.atrpms.net/all/libdvdcss2-1.2.10-5.fc15.i686.rpm"
	GetFile
	InstallFile
	SaveFile
	elif [ $(uname -i) = "x86_64" ]; then
	file="libdvdcss2-1.2.10-5.fc15.x86_64.rpm"
	get="http://dl.atrpms.net/all/libdvdcss2-1.2.10-5.fc15.x86_64.rpm"
	GetFile
	InstallFile
	SaveFile
	fi
fi
if [ -f /usr/lib/libdvdcss.so.2 ]; then
Success
else
Failure
fi
}

function InstallFlash()
{
echo -e $BLUEBOLD"Installing Flash Plugin"$ENDCOLOR
if [ -f /usr/lib64/mozilla/plugins/libflashplayer.so ] || [ -f /usr/lib/mozilla/plugins/libflashplayer.so ]; then
echo -e $GREEN"Flash plugin already installed"$ENDCOLOR
else
	if [ $(uname -i) = "i386" ]; then
	file="flash-plugin-11.0.1.152-release.i386.rpm"
	get="http://fpdownload.macromedia.com/get/flashplayer/pdc/11.0.1.152/flash-plugin-11.0.1.152-release.i386.rpm"
	GetFile
	InstallFile
	SaveFile
	elif [ $(uname -i) = "x86_64" ]; then
	file="flash-plugin-11.0.1.152-release.x86_64.rpm"
	get="http://fpdownload.macromedia.com/get/flashplayer/pdc/11.0.1.152/flash-plugin-11.0.1.152-release.x86_64.rpm"
	GetFile
	InstallFile
	SaveFile
	fi
fi
if [ -f /usr/lib64/mozilla/plugins/libflashplayer.so ] || [ -f /usr/lib/mozilla/plugins/libflashplayer.so ]; then
Success
else
Failure
fi
}

function InstallJava()
{
echo -e $BLUEBOLD"Installing Java Runtime Environment"$ENDCOLOR
if [ -e /usr/java/jre1.7.0_01/bin/java ]; then
echo -e $GREEN"Java already installed"$ENDCOLOR
else
	if [ $(uname -i) = "i386" ]; then
	file="jre-7u1-linux-i586.rpm"
	get="http://download.oracle.com/otn-pub/java/jdk/7u1-b08/jre-7u1-linux-i586.rpm"
	GetFile
	InstallFile
	echo -e "Setting up Java Plugin..."
	alternatives --install /usr/lib/mozilla/plugins/libjavaplugin.so libjavaplugin.so /usr/java/default/lib/i386/libnpjp2.so 20000
	SaveFile
	elif [ $(uname -i) = "x86_64" ]; then
	file="jre-7u1-linux-x64.rpm"
	get="http://download.oracle.com/otn-pub/java/jdk/7u1-b08/jre-7u1-linux-x64.rpm"
	GetFile
	InstallFile
	echo -e "Setting up Java Plugin..."
	alternatives --install /usr/lib64/mozilla/plugins/libjavaplugin.so libjavaplugin.so.x86_64 /usr/java/default/lib/amd64/libnpjp2.so 20000
	SaveFile
	fi
fi
if [ -e /usr/java/jre1.7.0_01/bin/java ]; then
echo -e "Configuring Java Runtime..."
cat <<EOF | tee /etc/profile.d/sunjava.sh
export JAVA_HOME=/usr/java/default
export PATH=\$JAVA_HOME/bin:\$PATH
EOF
fi
if [ -e /usr/java/jre1.7.0_01/bin/java ]; then
Success
else
Failure
fi
}

function InstallWine()
{
echo -e $BLUEBOLD"Installing Wine"$ENDCOLOR
RPMFusion
if [ -d /usr/lib/wine ]; then
echo -e $GREEN"Wine already installed"$ENDCOLOR
else
yum -y install --nogpgcheck wine
fi
if [ -d /usr/lib/wine ]; then
Success
else
Failure
fi
}

function WineGecko()
{
InstallWine
echo -e $BLUEBOLD"Installing Wine Gecko"$ENDCOLOR
if [ -f /usr/share/wine/gecko/wine_gecko* ]; then
echo -e $GREEN"Wine Gecko already installed"$ENDCOLOR
else
	if [ $(uname -i) = "i386" ]; then
	file="wine_gecko-1.3-x86.msi"
	get="http://downloads.sourceforge.net/wine/wine_gecko-1.2.0-x86.msi"
	GetFile
	mkdir -p /usr/share/wine/gecko
	cp "$file" /usr/share/wine/gecko/
	SaveFile
	elif [ $(uname -i) = "x86_64" ]; then
	file="wine_gecko-1.3-x86_64.msi"
	get="http://downloads.sourceforge.net/wine/wine_gecko-1.3-x86_64.msi"
	GetFile
	mkdir -p /usr/share/wine/gecko
	cp "$file" /usr/share/wine/gecko/
	SaveFile
	fi
fi
if [ -f /usr/share/wine/gecko/wine_gecko* ]; then
Success
else
Failure
fi
}

function GTalk()
{
echo -e $BLUEBOLD"Installing Gogle Talk"$ENDCOLOR
if [ -d /opt/google/talkplugin ]; then
echo -e $GREEN"Google Talk Plugin already installed"$ENDCOLOR
else
	if [ $(uname -i) = "i386" ]; then
	file="google-talkplugin_current_i386.rpm"
	get="http://dl.google.com/linux/direct/google-talkplugin_current_i386.rpm"
	GetFile
	InstallFile
	SaveFile
	elif [ $(uname -i) = "x86_64" ]; then
	file="google-talkplugin_current_x86_64.rpm"
	get="http://dl.google.com/linux/direct/google-talkplugin_current_x86_64.rpm"
	GetFile
	InstallFile
	SaveFile
	fi
fi
if [ -d /opt/google/talkplugin ]; then
Success
else
Failure
fi
}

function ColorTerm()
{
echo -e $BLUEBOLD"Enabling Colours in Terminal"$ENDCOLOR
s=`cat /etc/bashrc | grep -i "# Colors in Terminal"`
if [ -n "$s" ]; then
echo -e $GREEN"Colors already added"$ENDCOLOR
else
	if [ "$KEEPBACKUP" = "YES" ]; then
	cp /etc/bashrc /etc/bashrc.bak
	fi
cat <<EOF | tee -a /etc/bashrc
# Colors in Terminal
if [ \$USER = root ]; then
	PS1='\[\033[1;31m\][\u@\h \W]\\$\[\033[0m\] '
else
	PS1='\[\033[01;32m\]\u@\h\[\033[00m\] \[\033[01;34m\]\W\[\033[00m\]\[\033[1;32m\]\\$\[\033[m\] '
fi
EOF
fi
s=`cat /etc/bashrc | grep -i "# Colors in Terminal"`
if [ -n "$s" ]; then
Success
else
Failure
fi
}

function FortuneTerm()
{
echo -e $BLUEBOLD"Enabling Fortune Messsages in Terminal"$ENDCOLOR
RPMFusion
if [ ! -e /usr/bin/fortune ]; then
yum -y install --nogpgcheck fortune-mod
fi
s=`cat /etc/bashrc | grep -i "# Display Fortune"`
if [ -n "$s" ]; then
echo -e $GREEN"Fortune already installed"$ENDCOLOR
else
	if [ "$KEEPBACKUP" = "YES" ]; then
	cp /etc/bashrc /etc/bashrc.bak
	fi
cat <<EOF | tee -a /etc/bashrc
# Display Fortune
if [ "\$PS1" ]; then
fortune
fi
EOF
fi
s=`cat /etc/bashrc | grep -i "# Display Fortune"`
if [ -n "$s" ] && [ -e /usr/bin/fortune ]; then
Success
else
Failure
fi
}

function SELinuxPerm()
{
if [ "$KEEPBACKUP" = "YES" ]; then
cp /etc/selinux/config /etc/selinux/config.bak
fi
sed -i 's/SELINUX=enforcing/SELINUX=permissive/g' /etc/selinux/config
s=`cat /etc/selinux/config | grep -i "SELINUX=permissive"`
if [ -n "$s" ]; then
Success
else
Failure
fi
}

function SELinuxConf()
{
echo -e $BLUEBOLD"Setting SELinux to Permissive Mode"$ENDCOLOR
s=`cat /etc/selinux/config | grep -i "SELINUX=permissive"`
if [ -n "$s" ]; then
echo -e $GREEN"SELinux is already in permissive mode"$ENDCOLOR
else
	s=`cat /etc/selinux/config | grep -i "SELINUX=disabled"`
	if [ -n "$s" ]; then
	echo -e $GREEN"SELinux is disabled, not changing state"$ENDCOLOR
	else
	SELinuxPerm
	fi
fi
}

function ProcessFont()
{
font="$1"
fontfile="$WORKINGDIR/corefonts/$font"
if [ ! -f "$fontfile" ] || [ $FORCE = "YES" ]; then
echo -e $BLUE"Downloading $font..."$ENDCOLOR
curl -L -# "http://downloads.sourceforge.net/corefonts/$font" -o "$fontfile"
fi
cabextract -L -d "$WORKINGDIR/msttcorefonts" "$fontfile"
if [ "$KEEPDOWNLOADS" = "YES" ]; then
mv -f "$fontfile" "$DOWNLOADSDIR/corefonts/"
fi
}

function CoreFonts()
{
echo -e $BLUEBOLD"Installing Microsoft Truetype Fonts"$ENDCOLOR
if [ -d /usr/share/fonts/msttcorefonts ]; then
echo -e $GREEN"Microsoft Truetype fonts already installed"$ENDCOLOR
else
if [ ! -e /usr/bin/cabextract ]; then
yum -y install --nogpgcheck cabextract
fi
mkdir -p "$WORKINGDIR/corefonts"
ProcessFont andale32.exe
ProcessFont arialb32.exe
ProcessFont arial32.exe
ProcessFont comic32.exe
ProcessFont courie32.exe
ProcessFont georgi32.exe
ProcessFont impact32.exe
ProcessFont times32.exe
ProcessFont trebuc32.exe
ProcessFont verdan32.exe
ProcessFont webdin32.exe
mv "$WORKINGDIR/msttcorefonts" "/usr/share/fonts/"
echo -e $BLUE"Rebuilding Font Cache..."$ENDCOLOR
fc-cache -f -v
fi
if [ -d /usr/share/fonts/msttcorefonts ]; then
Success
else
Failure
fi
}

function InstallDKMS()
{
echo -e $BLUEBOLD"Installing dkms"$ENDCOLOR
if [ -d /usr/share/doc/dkms* ]; then
echo -e $GREEN"dkms is already installed"$ENDCOLOR
else
yum -y install --nogpgcheck dkms
fi
if [ -d /usr/share/doc/dkms* ]; then
Success
else
Failure
fi
}

function InstallJockey()
{
echo -e $BLUEBOLD"Installing Jockey Driver Installer"$ENDCOLOR
if [ -e /usr/bin/jockey-gtk ] || [ -e /usr/bin/jockey-kde ]; then
echo -e $GREEN"Jockey Driver Installer already installed"$ENDCOLOR
else
RPMFusion
ParsidoraRepo
if [ -f /etc/yum.repos.d/parsidora.repo ]; then
	if ( [ "$(pidof ksmserver)" ] ); then
	yum -y --enablerepo=parsidora install jockey-selinux jockey-kde
	else
	yum -y --enablerepo=parsidora install jockey-selinux jockey-gtk
	fi
fi
if [ -e /usr/bin/jockey-gtk ]; then
FixJockey
fi
fi
if [ -e /usr/bin/jockey-gtk ] || [ -e /usr/bin/jockey-kde ]; then
Success
else
Failure
fi
}

function EssentialSoft()
{
echo -e $BLUEBOLD"Installing Essential Software"$ENDCOLOR
if [ -e /usr/bin/beesu ]; then
echo -e $GREEN"beesu already installed"$ENDCOLOR
else
yum -y install --nogpgcheck beesu
fi
if [ -e /usr/bin/cabextract ]; then
echo -e $GREEN"cabextract already installed"$ENDCOLOR
else
yum -y install --nogpgcheck cabextract
fi
if [ -e /usr/bin/dconf-editor ]; then
echo -e $GREEN"dconf-editor already installed"$ENDCOLOR
else
yum -y install --nogpgcheck dconf-editor
fi
if [ -d /usr/share/doc/p7zip-plugins* ]; then
echo -e $GREEN"p7zip already installed"$ENDCOLOR
else
yum -y install --nogpgcheck p7zip p7zip-plugins
fi
if [ -e /usr/bin/wget ]; then
echo -e $GREEN"wget already installed"$ENDCOLOR
else
yum -y install --nogpgcheck wget
fi
if [ -e /usr/bin/lzma ]; then
echo -e $GREEN"lzma already installed"$ENDCOLOR
else
yum -y install --nogpgcheck xz-lzma-compat
fi
if [ -e /usr/bin/unrar ]; then
echo -e $GREEN"unrar already installed"$ENDCOLOR
else
yum -y install --nogpgcheck unrar
fi
if [ -e /usr/lib/yum-plugins/fastestmirror.py ]; then
echo -e $GREEN"yum-plugin-fastestmirror already installed"$ENDCOLOR
else
yum -y install --nogpgcheck yum-plugin-fastestmirror
fi
if [ -d /usr/share/doc/gnome-tweak-tool* ]; then
echo -e $GREEN"gnome-tweak-tool already installed"$ENDCOLOR
else
yum -y install --nogpgcheck gnome-tweak-tool
fi
if [ -e /usr/bin/beesu ] && [ -e /usr/bin/cabextract ] && [ -e /usr/bin/dconf-editor ] && [ -d /usr/share/doc/p7zip-plugins* ] && [ -e /usr/bin/wget ] && [ -e /usr/bin/lzma ] && [ -e /usr/bin/unrar ] && [ -e /usr/lib/yum-plugins/fastestmirror.py ] && [ -d /usr/share/doc/gnome-tweak-tool* ]; then
Success
else
Failure
fi
}

function SysUpdate()
{
echo -e $BLUEBOLD"Updating System"$ENDCOLOR
yum -y --skip-broken update
Done
Main
}

function FixFonts()
{
echo -e $BLUEBOLD"Fixing Font Smoothing"$ENDCOLOR
if [ ! -e /etc/fonts/conf.d/10-autohint.conf ]; then
ln -s /etc/fonts/conf.avail/10-autohint.conf /etc/fonts/conf.d/
fi
if [ ! -e /etc/fonts/conf.d/10-sub-pixel-rgb.conf ]; then
ln -s /etc/fonts/conf.avail/10-sub-pixel-rgb.conf /etc/fonts/conf.d/
fi
cat <<EOF | tee "$HOMEDIR/.fonts.conf"
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
 <match target="font">
 <edit name="autohint" mode="assign">
 <bool>true</bool>
 </edit>
 </match>
</fontconfig>
EOF
if [ -e "$HOMEDIR/.fonts.conf" ]; then
Success
else
Failure
fi
}

function FixTheme()
{
echo -e $BLUEBOLD"Fixing Bad theme in root Apps"$ENDCOLOR
if [ "$KEEPBACKUP" = "YES" ] && [ -e /root/.themes ]; then
mv /root/.themes /root/.themes.bak
fi
ln -sf $HOMEDIR/.themes/ /root
ln -sf $HOMEDIR/.icons/ /root
if [ -e /root/.themes ]; then
Success
else
Failure
fi
}

function FixRPMdb()
{
echo -e $BLUEBOLD"Fixing rpmdb"$ENDCOLOR
# Delete the rpmdb
rm -f /var/lib/rpm/__db*
# Rebuild the rpmdb
rpm --rebuilddb
Success
}

function FixKeyring()
{
echo -e $BLUEBOLD"Fixing Gnome Keyring"$ENDCOLOR
# Delete the keyring
rm -rf "$HOMEDIR/.gnome2/keyrings/*"
echo -e $YELLOW"You will be prompted for a new keyring password next time you login. Please give the same password as your login password to avoid further prompts. You can also leave it blank, but it is not recommended due to security concerns."$ENDCOLOR
if [ ! -e "$HOMEDIR/.gnome2/keyrings/*" ]; then
Success
else
Failure
fi
}

function FixPicasa()
{
echo -e $YELLOW"We need to install wine to fix Picasa 3.0 startup problem"$ENDCOLOR
InstallWine
echo -e $BLUEBOLD"Fixing Picasa"$ENDCOLOR
mv /opt/google/picasa/3.0/wine/lib/wine/wininet.dll.so /opt/google/picasa/3.0/wine/lib/wine/wininet.dll.so.bak
cp /usr/lib/wine/wininet.dll.so /opt/google/picasa/3.0/wine/lib/wine/
mv /opt/google/picasa/3.0/wine/bin/wine-preloader /opt/google/picasa/3.0/wine/bin/wine-preloader.bak
cp /usr/bin/wine-preloader /opt/google/picasa/3.0/wine/bin/
}

function FixJockey()
{
if [ "$fver" = "16" ]; then
cp /usr/bin/jockey-gtk /usr/bin/jockey-gtk.bak
echo -e $BLUE"Fixing Jockey Driver Installer"$ENDCOLOR
sed -i 's/import gobject/\# import gobject/g' /usr/bin/jockey-gtk
sed -i 's/gobject/GObject/g' /usr/bin/jockey-gtk
sed -i 's/from gi.repository import GdkPixbuf, Gtk, Notify/from gi.repository import GdkPixbuf, Gtk, Notify, GObject/g' /usr/bin/jockey-gtk
else
echo -e $YELLOW"The fix is not applicable to your Fedora Version"$ENDCOLOR
fi
}

function FixAnaconda()
{
if [ -e /usr/lib/anaconda-runtime/anaconda ]; then
echo -e $GREEN"Revisor already fixed"$ENDCOLOR
else
ln -s /usr/lib/anaconda /usr/lib/anaconda-runtime
fi
if [ -e /usr/lib/anaconda-runtime/anaconda ]; then
Success
else
Failure
fi
}

function FixMPlayer()
{
echo -e $BLUEBOLD"Fixing MPlayer Video Driver"$ENDCOLOR
s=`cat /etc/mplayer/mplayer.conf | grep -i "#vo=xv"`
if [ ! -n "$s" ]; then
echo -e $GREEN"Seems that a default driver is already specified for MPlayer"$ENDCOLOR
else
	if [ "$KEEPBACKUP" = "YES" ]; then
	cp /etc/mplayer/mplayer.conf /etc/mplayer/mplayer.conf.bak
	fi
sed -i 's/#vo=xv/vo=xv/g' /etc/mplayer/mplayer.conf
fi
s=`cat /etc/mplayer/mplayer.conf | grep -i "#vo=xv"`
if [ ! -n "$s" ]; then
Success
else
Failure
fi
}

function FixNTFS()
{
echo -e $BLUEBOLD"Fixing NTFS Config"$ENDCOLOR
if [ -d /etc/hal/fdi/policy ]; then
echo -e $GREEN"NTFS Config already fixed"$ENDCOLOR
else
mkdir -p /etc/hal/fdi/policy
fi
if [ -d /etc/hal/fdi/policy ]; then
Success
else
Failure
fi
}

function InstallBZR()
{
echo -e $BLUEBOLD"Installing BZR"$ENDCOLOR
if [ -d /usr/share/doc/bzr* ]; then
echo -e $GREEN"BZR already installed"$ENDCOLOR
else
yum -y install --nogpgcheck bzr
fi
if [ -d /usr/share/doc/bzr* ]; then
Success
else
Failure
fi
}

function InstallGIT()
{
echo -e $BLUEBOLD"Installing GIT"$ENDCOLOR
if [ -d /usr/share/doc/git* ]; then
echo -e $GREEN"GIT already installed"$ENDCOLOR
else
yum -y install --nogpgcheck git
fi
if [ -d /usr/share/doc/git* ]; then
Success
else
Failure
fi
}

function InstallGTKDev()
{
echo -e $BLUEBOLD"Installing Developement Packages for GTK3"$ENDCOLOR
yum -y install --nogpgcheck dbus-glib-devel glib2-devel gnome-common gtk3-devel intltool automake autoconf vala
}

function GPaste()
{
echo -e $BLUEBOLD"Installing GPaste"$ENDCOLOR
if [ -d /usr/share/gnome-shell/extensions/GPaste@gnome-shell-extensions.gnome.org ]; then
echo -e $GREEN"GPaste already installed"$ENDCOLOR
else
InstallGIT
InstallGTKDev
echo -e $YELLOW"We need to compile GPaste from source. It may take a while. Please be patient"$ENDCOLOR
git clone https://github.com/Keruspe/GPaste.git
cd GPaste
./autogen.sh
./configure --prefix=/usr --sysconfdir=/etc
make
make install
cd ..
fi
if [ -d /usr/share/gnome-shell/extensions/GPaste@gnome-shell-extensions.gnome.org ]; then
Success
else
Failure
fi
}

function MediaPlayer()
{
echo -e $BLUEBOLD"Installing Media Player Extension"$ENDCOLOR
if [ -d /usr/share/gnome-shell/extensions/mediaplayer@patapon.info ]; then
echo -e $GREEN"Media Player Extension already installed"$ENDCOLOR
else
InstallGIT
InstallGTKDev
echo -e $YELLOW"We need to compile Media Player Extension from source. It may take a while. Please be patient"$ENDCOLOR
git clone https://github.com/eonpatapon/gnome-shell-extensions-mediaplayer.git
cd gnome-shell-extensions-mediaplayer
./autogen.sh --prefix=/usr
make
make install
cd ..
fi
if [ -d /usr/share/gnome-shell/extensions/mediaplayer@patapon.info ]; then
Success
else
Failure
fi
}

function WeatherExtension()
{
echo -e $BLUEBOLD"Installing Weather Extension"$ENDCOLOR
if [ -d /usr/share/gnome-shell/extensions/weather@gnome-shell-extensions.gnome.org ]; then
echo -e $GREEN"Weather Extension is already installed"$ENDCOLOR
else
InstallGIT
InstallGTKDev
echo -e $YELLOW"We need to compile Weather extension from source. It may take a while. Please be patient"$ENDCOLOR
git clone https://github.com/simon04/gnome-shell-extension-weather.git
cd gnome-shell-extension-weather
./autogen.sh
./configure --prefix=/usr
make
make install
cd ..
fi
if [ -d /usr/share/gnome-shell/extensions/weather@gnome-shell-extensions.gnome.org ]; then
Success
else
Failure
fi
}

function SysMonitor()
{
echo -e $BLUEBOLD"Installing System Monitor Extension"$ENDCOLOR
if [ -d /usr/share/gnome-shell/extensions/system-monitor@paradoxxx.zero.gmail.com ]; then
echo -e $GREEN"System Monitor Extension is already installed"$ENDCOLOR
else
InstallGIT
InstallGTKDev
yum -y install --nogpgcheck python3 python3-gobject
echo -e $YELLOW"We need to compile System Monitor extension from source. It may take a while. Please be patient"$ENDCOLOR
git clone https://github.com/paradoxxxzero/gnome-shell-system-monitor-applet.git
cd gnome-shell-system-monitor-applet
./install
cd ..
fi
if [ -d /usr/share/gnome-shell/extensions/system-monitor@paradoxxx.zero.gmail.com ]; then
Success
else
Failure
fi
}

function PidginShell()
{
echo -e $BLUEBOLD"Installing Pidgin Notifier Extension"$ENDCOLOR
if [ -d /usr/share/gnome-shell/extensions/pidgin@gnome-shell-extensions.gnome.org ]; then
echo -e $GREEN"Pidgin Notifier Extension is already installed"$ENDCOLOR
else
InstallGIT
git clone https://github.com/kagesenshi/gnome-shell-extensions-pidgin.git
mv gnome-shell-extensions-pidgin /usr/share/gnome-shell/extensions/pidgin@gnome-shell-extensions.gnome.org
fi
if [ -d /usr/share/gnome-shell/extensions/pidgin@gnome-shell-extensions.gnome.org ]; then
Success
else
Failure
fi
}

function AltStatusMenu()
{
echo -e $BLUEBOLD"Installing Alternative Status Menu"$ENDCOLOR
if [ -d /usr/share/gnome-shell/extensions/alternative-status-menu@gnome-shell-extensions.gnome.org ]; then
echo -e $GREEN"Alternative Status Menu Extension is already installed"$ENDCOLOR
else
yum -y install --nogpgcheck gnome-shell-extensions-alternative-status-menu
fi
if [ -d /usr/share/gnome-shell/extensions/alternative-status-menu@gnome-shell-extensions.gnome.org ]; then
Success
else
Failure
fi
}


function PlacesMenu()
{
echo -e $BLUEBOLD"Installing Places Menu"$ENDCOLOR
if [ -d /usr/share/gnome-shell/extensions/places-menu@gnome-shell-extensions.gnome.org ]; then
echo -e $GREEN"Places Menu Extension is already installed"$ENDCOLOR
else
yum -y install --nogpgcheck gnome-shell-extensions-places-menu
fi
if [ -d /usr/share/gnome-shell/extensions/places-menu@gnome-shell-extensions.gnome.org ]; then
Success
else
Failure
fi
}

function UserTheme()
{
echo -e $BLUEBOLD"Installing User Theme Extension"$ENDCOLOR
if [ -d /usr/share/gnome-shell/extensions/user-theme@gnome-shell-extensions.gnome.org ]; then
echo -e $GREEN"User Theme Extension is already installed"$ENDCOLOR
else
yum -y install --nogpgcheck gnome-shell-extensions-user-theme
fi
if [ -d /usr/share/gnome-shell/extensions/user-theme@gnome-shell-extensions.gnome.org ]; then
Success
else
Failure
fi
}

function WindowsNavigator()
{
echo -e $BLUEBOLD"Installing Window Navigator"$ENDCOLOR
if [ -d /usr/share/gnome-shell/extensions/windowsNavigator@gnome-shell-extensions.gnome.org ]; then
echo -e $GREEN"Window Navigator Extension is already installed"$ENDCOLOR
else
yum -y install --nogpgcheck gnome-shell-extensions-windowsNavigator
fi
if [ -d /usr/share/gnome-shell/extensions/windowsNavigator@gnome-shell-extensions.gnome.org ]; then
Success
else
Failure
fi
}

function Zeitgeist()
{
echo -e $BLUEBOLD"Installing Zeigeist Extension"$ENDCOLOR
if [ -d /usr/share/gnome-shell/extensions/gimmie@gnome-shell-extensions.gnome.org ]; then
echo -e $GREEN"Zeigeist Extension is already installed"$ENDCOLOR
else
yum -y install --nogpgcheck zeitgeist zeitgeist-datahub
file="gimmie@gnome-shell-extensions.gnome.org.zip"
get="http://dl.dropbox.com/u/7162902/gimmie@gnome-shell-extensions.gnome.org.zip"
GetFile
unzip "$file"
mv gimmie@gnome-shell-extensions.gnome.org /usr/share/gnome-shell/extensions/
SaveFile
fi
if [ -d /usr/share/gnome-shell/extensions/gimmie@gnome-shell-extensions.gnome.org ]; then
Success
else
Failure
fi
}

function InstallGoogleChrome()
{
echo -e $BLUEBOLD"Installing Google Chrome"$ENDCOLOR
if [ -d /opt/google/chrome ]; then
echo -e $GREEN"Google Chrome already installed"$ENDCOLOR
else
	if [ $(uname -i) = "i386" ]; then
	file="google-chrome-stable_current_i386.rpm"
	get="http://dl.google.com/linux/direct/google-chrome-stable_current_i386.rpm"
	GetFile
	InstallFile
	SaveFile
	elif [ $(uname -i) = "x86_64" ]; then
	file="google-chrome-stable_current_x86_64.rpm"
	get="http://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm"
	GetFile
	InstallFile
	SaveFile
	fi
fi
if [ -d /opt/google/chrome ]; then
Success
else
Failure
fi
}

function InstallPicasa()
{
echo -e $BLUEBOLD"Installing Picasa"$ENDCOLOR
if [ -e /opt/google/picasa ]; then
echo -e $GREEN"Picasa already installed"$ENDCOLOR
else
file="picasa-3.0-current.i386.rpm"
get="http://dl.google.com/linux/rpm/testing/i386/picasa-3.0-current.i386.rpm"
GetFile
InstallFile
SaveFile
FixPicasa
fi
if [ -e /opt/google/picasa ]; then
Success
else
Failure
fi
}

function InstallGoogleEarth()
{
echo -e $BLUEBOLD"Installing Google Earth"$ENDCOLOR
if [ -d /opt/google/earth/ ]; then
echo -e $GREEN"Google Earth already installed"$ENDCOLOR
else
yum -y install --nogpgcheck mesa-libGL.i686 bitstream-vera-fonts-common libxml2.i686 gtk2.i686 libSM.i686 qt-x11 redhat-lsb-graphics redhat-lsb-printing redhat-lsb.i686
file="GoogleEarthLinux.bin"
get="http://dl.google.com/earth/client/current/GoogleEarthLinux.bin"
GetFile
chmod +x "$file"
./"$file"
restorecon -R -v /opt/googleearth
restorecon -R -v /usr/lib/googleearth
SaveFile
fi
if [ -d /opt/google/earth/ ]; then
Success
else
Failure
fi
}

function InstallJupiter()
{
echo -e $BLUEBOLD"Installing Jupiter"$ENDCOLOR
if [ -e /usr/bin/jupiter.exe ]; then
echo -e $GREEN"Jupiter already installed"$ENDCOLOR
else
file="jupiter-0.0.51-3.noarch.rpm"
get="http://master.dl.sourceforge.net/project/jupiter/jupiter-0.0.51-3.noarch.rpm"
GetFile
InstallFile
SaveFile
fi
if [ -e /usr/bin/jupiter.exe ]; then
Success
else
Failure
fi
}

function InstallHandBrake()
{
echo -e $BLUEBOLD"Installing HandBrake"$ENDCOLOR
if [ -d /usr/share/doc/HandBrake* ]; then
echo -e $GREEN"HandBrake already installed"$ENDCOLOR
else
	if [ "$fver" = "15" ] || [ "$fver" = "16" ]; then
		if [ $(uname -i) = "i386" ]; then
		file="HandBrake-0.9.5-1-Fedora15_GUI_i686.rpm"
		get="http://master.dl.sourceforge.net/project/handbrake/0.9.5/HandBrake-0.9.5-1-Fedora15_GUI_i686.rpm"
		GetFile
		InstallFile
		SaveFile
		elif [ $(uname -i) = "x86_64" ]; then
		file="HandBrake-0.9.5-1-Fedora15_GUI_x86_64.rpm"
		get="http://master.dl.sourceforge.net/project/handbrake/0.9.5/HandBrake-0.9.5-1-Fedora15_GUI_x86_64.rpm"
		GetFile
		InstallFile
		SaveFile
		fi
	else
		if [ $(uname -i) = "i386" ]; then
		file="HandBrake-0.9.5-Fedora_GUI_i686.rpm"
		get="http://master.dl.sourceforge.net/project/handbrake/0.9.5/HandBrake-0.9.5-Fedora_GUI_i686.rpm"
		GetFile
		InstallFile
		SaveFile
		elif [ $(uname -i) = "x86_64" ]; then
		file="HandBrake-0.9.5-Fedora_GUI_x86_64.rpm"
		get="http://master.dl.sourceforge.net/project/handbrake/0.9.5/HandBrake-0.9.5-Fedora_GUI_x86_64.rpm"
		GetFile
		InstallFile
		SaveFile
		fi
	fi
fi
if [ -d /usr/share/doc/HandBrake* ]; then
Success
else
Failure
fi
}

function InstallSkype()
{
echo -e $BLUEBOLD"Installing Skype"$ENDCOLOR
if [ -e /usr/bin/skype ]; then
echo -e $GREEN"Skype already installed"$ENDCOLOR
else
file="skype-2.2.0.35-fedora.i586.rpm"
get="http://download.skype.com/linux/skype-2.2.0.35-fedora.i586.rpm"
GetFile
yum -y install --nogpgcheck qt.i686 qt-x11.i686 libXv.i686 libXScrnSaver.i686
InstallFile
SaveFile
fi
if [ -e /usr/bin/skype ]; then
Success
else
Failure
fi
}

function InstallWinFF()
{
echo -e $BLUEBOLD"Installing WinFF"$ENDCOLOR
if [ -d /usr/share/winff ]; then
echo -e $GREEN"WinFF already installed"$ENDCOLOR
else
yum -y install ffmpeg
file="winff-1.3.2-4.i386.rpm"
get="http://winff.googlecode.com/files/winff-1.3.2-4.i386.rpm"
GetFile
InstallFile
SaveFile
fi
if [ -d /usr/share/winff ]; then
Success
else
Failure
fi
}

function InstallJDK()
{
echo -e $BLUEBOLD"Installing Oracle JDK"$ENDCOLOR
if [ -e /usr/java/jdk1.7.0_01/bin/java ]; then
echo -e $GREEN"Oracle JDK already installed"$ENDCOLOR
else
	if [ $(uname -i) = "i386" ]; then
	file="jdk-7u1-linux-i586.rpm"
	get="http://download.oracle.com/otn-pub/java/jdk/7u1-b08/jdk-7u1-linux-i586.rpm"
	GetFile
	InstallFile
	echo -e "Setting up Oracle JDK..."
	## java ##
	alternatives --install /usr/bin/java java /usr/java/jdk1.7.0_01/jre/bin/java 20000
	## javaws ##
	alternatives --install /usr/bin/javaws javaws /usr/java/jdk1.7.0_01/jre/bin/javaws 20000 
	## Install javac ##
	alternatives --install /usr/bin/javac javac /usr/java/jdk1.7.0_01/bin/javac 20000
	alternatives --install /usr/bin/jar jar /usr/java/jdk1.7.0_01/bin/jar 20000
	## Java Browser (Mozilla) Plugin 32-bit ##
	alternatives --install /usr/lib/mozilla/plugins/libjavaplugin.so libjavaplugin.so /usr/java/jdk1.7.0_01/jre/lib/i386/libnpjp2.so 20000
	SaveFile
	elif [ $(uname -i) = "x86_64" ]; then
	file="jdk-7u1-linux-x64.rpm"
	get="http://download.oracle.com/otn-pub/java/jdk/7u1-b08/jdk-7u1-linux-x64.rpm"
	GetFile
	InstallFile
	echo -e "Setting up Oracle JDK..."
	## java ##
	alternatives --install /usr/bin/java java /usr/java/jdk1.7.0_01/jre/bin/java 20000
	## javaws ##
	alternatives --install /usr/bin/javaws javaws /usr/java/jdk1.7.0_01/jre/bin/javaws 20000 
	## Install javac ##
	alternatives --install /usr/bin/javac javac /usr/java/jdk1.7.0_01/bin/javac 20000
	alternatives --install /usr/bin/jar jar /usr/java/jdk1.7.0_01/bin/jar 20000
	## Java Browser (Mozilla) Plugin 64-bit ##
	alternatives --install /usr/lib64/mozilla/plugins/libjavaplugin.so libjavaplugin.so.x86_64 /usr/java/jdk1.7.0_01/jre/lib/amd64/libnpjp2.so 20000
	SaveFile
	fi
fi
if [ -e /usr/java/jdk1.7.0_01/bin/java ]; then
echo -e "Configuring Java Runtime..."
cat <<EOF | tee /etc/profile.d/sunjava.sh
export JAVA_HOME=/usr/java/default
export PATH=\$JAVA_HOME/bin:\$PATH
EOF
fi
if [ -e /usr/java/jdk1.7.0_01/bin/java ]; then
Success
else
Failure
fi
}

function InstallUnico()
{
echo -e $BLUEBOLD"Installing Unico Theme Engine"$ENDCOLOR
if [ -e /usr/lib/gtk-3.0/3.0.0/theming-engines/libunico.so ]; then
echo -e $GREEN"Unico Theme Engine already installed"$ENDCOLOR
else
InstallBZR
InstallGTKDev
	if [ "$fver" = "15" ]; then
	echo -e $YELLOW"We need to compile Unico Theme Engine from source. It may take a while. Please be patient"$ENDCOLOR
	bzr co -r 69 lp:unico
	cd unico
	./autogen.sh
	./configure --prefix=/usr
	make
	make install
	cd ..
	elif [ "$fver" = "16" ]; then
	echo -e $YELLOW"We need to compile Unico Theme Engine from source. It may take a while. Please be patient"$ENDCOLOR
	bzr branch lp:unico
	cd unico
	./autogen.sh
	./configure --prefix=/usr
	make
	make install
	cd ..
	else
	echo -e $YELLOW"Unico Theme Engine is not available for your Fedora version"$ENDCOLOR
	fi
fi
if [ -e /usr/lib/gtk-3.0/3.0.0/theming-engines/libunico.so ]; then
Success
else
Failure
fi
}

function SysInfo()
{
zenity --info --width=400 --height=400 --title="System Information" --text="Distribution: $(cat /etc/fedora-release)\n\nKernel: $(uname -s -r)\n\nArchitecture: $(uname -i)\n\nRAM: $(cat /proc/meminfo | grep MemTotal | cut -c10-)\n\nGraphics: $(lspci -s 00:02.0)\n\nUptime: $(uptime)"
Main
}

function InstallFedoraUtils()
{
if [ -e /usr/bin/fedorautils ] && [ -e /usr/share/fedorautils/fedorautils ]; then
echo -e $BLUEBOLD"Removing Fedora Utils"$ENDCOLOR
yum -y erase fedorautils
	if [ ! -e /usr/bin/fedorautils ] && [ ! -e /usr/share/fedorautils/fedorautils ]; then
	Success
	else
	Failure
	fi
else
echo -e $BLUEBOLD"Installing Fedora Utils"$ENDCOLOR
yum -y localinstall --nogpgcheck http://fedorautils.sourceforge.net/fedorautils-latest.noarch.rpm
	if [ -e /usr/bin/fedorautils ] && [ -e /usr/share/fedorautils/fedorautils ]; then
	Success
	else
	Failure
	fi
fi
}

function FedoraUtilsRepo()
{
if [ -e /etc/yum.repos.d/fedorautils.repo ]; then
echo -e $BLUEBOLD"Removing Fedora Utils Repo"$ENDCOLOR
rm -f /etc/yum.repos.d/fedorautils.repo
	if [ ! -e /etc/yum.repos.d/fedorautils.repo ]; then
	Success
	else
	Failure
	fi
else
echo -e $BLUEBOLD"Adding Fedora Utils Repo"$ENDCOLOR
curl -s http://fedorautils.sourceforge.net/repo/fedorautils.repo -o /etc/yum.repos.d/fedorautils.repo
	if [ -e /etc/yum.repos.d/fedorautils.repo ]; then
	Success
	else
	Failure
	fi
fi
}

function Help()
{
# Detect Status
if [ -e /usr/bin/fedorautils ] && [ -e /usr/share/fedorautils/fedorautils ]; then
INSTALLTEXT="Uninstall"
else
INSTALLTEXT="Install"
fi
if [ -e /etc/yum.repos.d/fedorautils.repo ]; then
REPOTEXT="Remove"
else
REPOTEXT="Add"
fi
shell=$(zenity --list --width=300 --height=300 --title="$PROGRAM - Help" --radiolist  --column "Select" --column "Options" FALSE "$INSTALLTEXT Fedora Utils Package" FALSE "$REPOTEXT Fedora Utils Repo" FALSE "Revert Changes" FALSE "Visit FAQ" FALSE "View Changelog" FALSE "Version Info" --separator=":")
if [ $? == 1 ]; then
	Main
fi
arr=$(echo $shell | tr "\:" "\n")
for x in $arr
do
	if [ $x = "Package" ]; then
	InstallFedoraUtils
	fi
	if [ $x = "Repo" ]; then
	FedoraUtilsRepo
	fi
	if [ $x = "Revert" ]; then
	echo -e $BLUE"Opening Browser..."$ENDCOLOR
	python -mwebbrowser "http://fedorautils.sourceforge.net/revert.html"
	fi
	if [ $x = "FAQ" ]; then
	echo -e $BLUE"Opening Browser..."$ENDCOLOR
	python -mwebbrowser "http://fedorautils.sourceforge.net/faq.html"
	fi
	if [ $x = "Changelog" ]; then
	echo -e $BLUE"Fetching Changelog..."$ENDCOLOR
	curl -s http://fedorautils.sourceforge.net/README -o changelog
		if [ -e changelog ]; then
		zenity --text-info --width=600 --height=600 --title="Changelog" --filename=changelog
		rm -f changelog
		else
		echo -e $RED"Error fetching changelog! Do you have an active internet connection?"$ENDCOLOR
		fi	
	fi
	if [ $x = "Version" ]; then
	zenity --info --title="Version Information" --text="Current Version: $VERSION\n\nLatest: $latest"
	fi
done
Done
Main
}

function OptimizeBoot()
{
zenity --question --title="Warning!" --text="This turns off some system daemons. You will be presented with a list. Though the default selections should suit most people, it is recommended to carefully review and select only the daemons you don't need. Sure to Proceed?" --ok-label "I Understand the Risks" --cancel-label "I'll Do it Later"
if [ $? = 1 ]; then
	Main
fi
daemons=$(zenity --list --width=750 --height=600 --title="$PROGRAM - Disable Unnecessary Daemons" --checklist  --column "Select" --column "Options" --column "Description" FALSE "abrt" "Manages application crashes" FALSE "bluetooth" "Required for Bluetooth" FALSE "cpuspeed" "Sets the CPU Speed according to the system load" FALSE "cups" "Starts the Printing Service" FALSE "httpd" "Starts the Apache HTTP Server" TRUE "fcoe" "Required if you have fibre channel over ethernet devices" TRUE "firstboot" "Performs certain tasks once upon booting after installation" FALSE "iptables" "Recommended if you are directly connected to internet" TRUE "ip6tables" "Used in ipv6" TRUE "irda" "Required for Infrared" TRUE "iscsi" "Required if you have iSCSI devices" TRUE "iscsid" "Implements the control path of iSCSI protocol" TRUE "livesys" "Only needed for the Live CD" TRUE "livesys-late" "Only needed in the Live Session" TRUE "lldpad" "Executes the LLDP protocol" TRUE "mdmonitor" "Monitors Software RAID or LVM information" FALSE "mysqld" "Starts the MySQL Service" FALSE "netfs" "Useful if you connect to another server or filesharing on your local network" FALSE "netconsole" "Initializes network console logging" FALSE "ntpd" "Starts the Network Time Protocol" TRUE "ntpdate" "Synchronizes date with a NTP Server" TRUE "pppoe-server" "User-space server for Point-to-Point Protocol over Ethernet" TRUE "psacct" "Monitors several utilities" TRUE "rsyslog" "Handles logging in server environments" TRUE "saslauthd" "Handles SASL plaintext authentication requests in servers using SASL" TRUE "sendmail" "Starts the Sendmail Service" TRUE "smolt" "Gathers & Sends info about your system to Fedora devs on a monthly basis" TRUE "wpa_supplicant" "Required if you use a wireless card that requires WPA based encryption" --separator=":")
if [ $? == 1 ]; then
	Main
fi
echo -e $BLUE"Optimizing Boot Process..."$ENDCOLOR
arr=$(echo $daemons | tr "\:" "\n")
for x in $arr
do	
	if [ $x = "abrtd" ]; then
	chkconfig abrtd off
	fi
	if [ $x = "bluetooth" ]; then
	chkconfig bluetooth off
	fi
	if [ $x = "cpuspeed" ]; then
	chkconfig cpuspeed off
	fi
	if [ $x = "cups" ]; then
	chkconfig cups off
	fi
	if [ $x = "httpd" ]; then
	chkconfig httpd off
	fi
	if [ $x = "fcoe" ]; then
	chkconfig fcoe off
	fi
	if [ $x = "firstboot" ]; then
	chkconfig firstboot off
	fi
	if [ $x = "iptables" ]; then
	chkconfig iptables off
	fi
	if [ $x = "ip6tables" ]; then
	chkconfig ip6tables off
	fi
	if [ $x = "irda" ]; then
	chkconfig irda off
	fi
	if [ $x = "iscsi" ]; then
	chkconfig iscsi off
	fi
	if [ $x = "iscsid" ]; then
	chkconfig iscsid off
	fi
	if [ $x = "livesys" ]; then
	chkconfig livesys off
	fi
	if [ $x = "livesys-late" ]; then
	chkconfig livesys-late off
	fi
	if [ $x = "lldpad" ]; then
	chkconfig lldpad off
	fi
	if [ $x = "mdmonitor" ]; then
	chkconfig mdmonitor off
	fi
	if [ $x = "mysqld" ]; then
	chkconfig mysqld off
	fi
	if [ $x = "netfs" ]; then
	chkconfig netfs off
	fi
	if [ $x = "netconsole" ]; then
	chkconfig netconsole off
	fi
	if [ $x = "ntpd" ]; then
	chkconfig ntpd off
	fi
	if [ $x = "ntpdate" ]; then
	chkconfig ntpdate off
	fi
	if [ $x = "pppoe-server" ]; then
	chkconfig pppoe-server off
	fi
	if [ $x = "psacct" ]; then
	chkconfig psacct off
	fi
	if [ $x = "rsyslog" ]; then
	chkconfig rsyslog off
	fi
	if [ $x = "saslauthd" ]; then
	chkconfig saslauthd off
	fi
	if [ $x = "sendmail" ]; then
	chkconfig sendmail off
	fi
	if [ $x = "smolt" ]; then
	chkconfig smolt off
	fi
	if [ $x = "wpa_supplicant" ]; then
	chkconfig wpa_supplicant off
	fi
done
REBOOTREQUIRED="YES"
Done
Main
}

function CleanUp()
{
shell=$(zenity --list --width=350 --height=400 --title="$PROGRAM - Clean Up" --text="Clean up your system and free up space.\nthese options affect all users.\nUse at your own risk." --checklist  --column "Select" --column "Options" FALSE "Delete Backup Files" FALSE "Delete Empty Folders" FALSE "Remove Old Kernels" FALSE "Remove Duplicate Packages" FALSE "Erase Bash History" FALSE "Empty Trash" FALSE "Delete Fedora Utils Logs" --separator=":")
if [ $? == 1 ]; then
	Main
fi
arr=$(echo $shell | tr "\:" "\n")
for x in $arr
do
	if [ $x = "Backup" ]; then
	echo -e $BLUEBOLD"Deleting Backup Files..."$ENDCOLOR
	find /home/ -name '*~' -delete
	find /home/ -name '*.bak' -delete
	fi
	if [ $x = "Empty" ]; then
	echo -e $BLUEBOLD"Deleting Empty Folders..."$ENDCOLOR
	find /home/ -type d -empty -delete
	fi
	if [ $x = "Kernels" ]; then
	echo -e $BLUEBOLD"Removing Old Kernel..."$ENDCOLOR
	package-cleanup --oldkernels --count=1
	REBOOTREQUIRED="YES"
	fi
	if [ $x = "Duplicate" ]; then
	echo -e $BLUEBOLD"Removing Duplicate Packages..."$ENDCOLOR
	package-cleanup --cleandupes
	fi
	if [ $x = "Bash History" ]; then
	echo -e $BLUEBOLD"Erasing Bash History..."$ENDCOLOR
	rm -f /home/*/.bash_history
	rm -f /root/*/.bash_history
	fi
	if [ $x = "Trash" ]; then
	echo -e $BLUEBOLD"Emptying Trash..."$ENDCOLOR
	rm -rf /home/*/.local/share/Trash/*
	rm -rf /root/.local/share/Trash/*
	fi
	if [ $x = "Utils" ]; then
	echo -e $BLUEBOLD"Deleting Fedora Utils Log Files..."$ENDCOLOR
	rm -f "$LOGFILE" "$LOGFILE"-*
	fi
done
Done
Main
}

function ShellExtensions()
{
shell=$(zenity --list --width=350 --height=500 --title="$PROGRAM - Install Shell Extensions" --text="Extensions can enhance the functionality of Gnome Shell,\nbut poorly written extensions may also cause problems.\nInstall Gnome Tweak Tool to manage the extensions" --checklist  --column "Select" --column "Options" TRUE "Alternative Status Menu" FALSE "Places Menu" TRUE "User Theme" TRUE "Window Navigator" FALSE "Pidgin Notifier" FALSE "Zeitgeist Extension" FALSE "System Monitor" FALSE "GPaste Clipboard Manager" FALSE "Media Player Extension" FALSE "Weather Extension" --separator=":")
if [ $? == 1 ]; then
	Main
fi
arr=$(echo $shell | tr "\:" "\n")
for x in $arr
do
	if [ $x = "Status" ]; then
	AltStatusMenu
	fi
	if [ $x = "Places" ]; then
	PlacesMenu
	fi
	if [ $x = "Theme" ]; then
	UserTheme
	fi
	if [ $x = "Navigator" ]; then
	WindowsNavigator
	fi
	if [ $x = "Pidgin" ]; then
	PidginShell
	fi
	if [ $x = "Zeitgeist" ]; then
	Zeitgeist
	fi
	if [ $x = "System" ]; then
	SysMonitor
	fi
	if [ $x = "Player" ]; then
	MediaPlayer
	fi
	if [ $x = "Weather" ]; then
	WeatherExtension
	fi
	if [ $x = "GPaste" ]; then
	GPaste
	fi
done
echo -e $YELLOW"Please restart Gnome Shell by pressing ALT+F2 and enter r"$ENDCOLOR
echo -e $YELLOW"For safety purposes, the extensions are not enabled by default, but you can enable them in Gnome Tweak Tool"$ENDCOLOR
Done
Main
}

function InstallSoft()
{
apps=$(zenity --list --width=350 --height=400 --title="$PROGRAM - Install Software" --text="Select the Softwares to Install." --checklist  --column "Select" --column "Options" TRUE "Google Chrome" FALSE "Google Picasa" FALSE "Google Earth" FALSE "Jupiter" FALSE "HandBrake" TRUE "Skype" FALSE "LibreOffice Suite" FALSE "WinFF" FALSE "Oracle JDK" TRUE "Unico Theme Engine" --separator=":")
if [ $? == 1 ]; then
	Main
fi
arr=$(echo $apps | tr "\:" "\n")
for x in $arr
do
	if [ $x = "Chrome" ]; then
	InstallGoogleChrome
	fi
	if [ $x = "Picasa" ]; then
	InstallPicasa
	fi
	if [ $x = "Earth" ]; then
	InstallGoogleEarth
	fi
	if [ $x = "Jupiter" ]; then
	InstallJupiter
	fi
	if [ $x = "HandBrake" ]; then
	InstallHandBrake
	fi
	if [ $x = "Skype" ]; then
	InstallSkype
	fi
	if [ $x = "LibreOffice" ]; then
	yum -y groupinstall "Office/Productivity"
	fi
	if [ $x = "WinFF" ]; then
	InstallWinFF
	fi
	if [ $x = "JDK" ]; then
	InstallJDK
	fi
	if [ $x = "Unico" ]; then
	InstallUnico
	fi
done
Done
Main
}

function FixProblems()
{
fix=$(zenity --list --width=300 --height=400 --title="$PROGRAM - Fix Problems" --text="Choose the following only if you face a problem." --checklist  --column "Select" --column "Options" FALSE "Fix Font Smoothing" FALSE "Fix bad theme in root apps" FALSE "Fix rpmdb open failed Error" FALSE "Fix Keyring password prompt" FALSE "Fix Picasa 3.0 Not Starting" FALSE "Fix Jockey (Fedora 16)" FALSE "Fix Anaconda Runtime & Revisor" FALSE "Fix MPlayer Driver Error" FALSE "Fix NTFS Config" --separator=":")
if [ $? == 1 ]; then
	Main
fi
arr=$(echo $fix | tr "\:" "\n")
for x in $arr
do
	if [ $x = "Font" ]; then
	FixFonts
	fi
	if [ $x = "theme" ]; then
	FixTheme
	fi
	if [ $x = "rpmdb" ]; then
	FixRPMdb
	fi
	if [ $x = "Keyring" ]; then
	FixKeyring
	fi
	if [ $x = "Picasa" ]; then
	FixPicasa
	fi
	if [ $x = "Jockey" ]; then
	FixJockey
	fi
	if [ $x = "Anaconda" ]; then
	FixAnaconda
	fi
	if [ $x = "MPlayer" ]; then
	FixMPlayer
	fi
	if [ $x = "NTFS" ]; then
	FixNTFS
	fi
done
Done
Main
}

function DetectStatus()
{
echo -e $BLUEBOLD"Detecting system status"$ENDCOLOR
# Yum Cache Status
s=`cat /etc/yum.conf | grep -i "keepcache=1"`
if [ -n "$s" ]; then
	YUMSTAT="Set to Keep Cache"
else
	YUMSTAT="Set Not to Keep Cache"
fi
# Tidy Cache Plugin Status
if [ -f /usr/lib/yum-plugins/tidy-cache.py ]; then
	TIDYCACHESTAT="Installed"
else
	TIDYCACHESTAT="Not Installed"
fi
# Autologin Status
s=`cat /etc/gdm/custom.conf | grep -i "AutomaticLoginEnable=True"`
if [ -n "$s" ]; then
	AUTOLOGINSTAT="Enabled"
else
	AUTOLOGINSTAT="Not Enabled"
fi
# Repos Status
if [ -f /etc/yum.repos.d/rpmfusion-free.repo ] && [ -f /etc/yum.repos.d/rpmfusion-nonfree.repo ] && [ -f /etc/yum.repos.d/google.repo ] && [ -f /etc/yum.repos.d/fedora-chromium.repo ] && [ -f /etc/yum.repos.d/skype.repo ]; then
	REPOSTAT="Added"
else
	REPOSTAT="Not Added"
fi
# Touchpad Status
if [ -f /etc/X11/xorg.conf.d/00-enable-taps.conf ]; then
	TOUCHPADSTAT="Enabled"
else
	TOUCHPADSTAT="Not Enabled"
fi
# Codecs Status
if [ -d /usr/share/doc/gstreamer-plugins-ugly* ] && [ -d /usr/local/lib/codecs ]; then
	CODECSTAT="Installed"
else
	CODECSTAT="Not Installed"
fi
# DVD Codecs
if [ -f /usr/lib/libdvdcss.so.2 ]; then
	DVDSTAT="Enabled"
else
	DVDSTAT="Not Enabled"
fi
# Flash Plugin Status
if [ -f /usr/lib/mozilla/plugins/libflashplayer.so ] || [ -f /usr/lib64/mozilla/plugins/libflashplayer.so ]; then
	FLASHSTAT="Installed"
else
	FLASHSTAT="Not Installed"
fi
# Java status
if [ -e /usr/java/jre1.7.0_01/bin/java ]; then
	JAVASTAT="Installed"
else
	JAVASTAT="Not Installed"
fi
# Wine Gecko Status
if [ -f /usr/share/wine/gecko/wine_gecko* ]; then
	GECKOSTAT="Installed"
else
	GECKOSTAT="Not Installed"
fi
# GTalk Status
if [ -d /opt/google/talkplugin ]; then
	GTALKSTAT="Installed"
else
	GTALKSTAT="Not Installed"
fi
# Colors in Terminal
s=`cat /etc/bashrc | grep -i "# Colors in Terminal"`
if [ -n "$s" ]; then
	COLORSTAT="Added"
else
	COLORSTAT="Not Added"
fi
# Fortune in Terminal
s=`cat /etc/bashrc | grep -i "# Display Fortune"`
if [ -n "$s" ] && [ -e /usr/bin/fortune ]; then
	FORTUNESTAT="Added"
else
	FORTUNESTAT="Not Added"
fi
# SELinux Status
s=`cat /etc/selinux/config | grep -i "SELINUX=permissive"`
if [ -n "$s" ]; then
	SESTAT="Permissive Mode"
else
	s=`cat /etc/selinux/config | grep -i "SELINUX=disabled"`
	if [ -n "$s" ]; then
		SESTAT="Disabled"
	else
		SESTAT="Not Configured"
	fi
fi
# Fonts Status
if [ -d /usr/share/fonts/msttcorefonts ]; then
	FONTSTAT="Installed"
else
	FONTSTAT="Not Installed"
fi
# Jockey Status
if [ -e /usr/bin/jockey-gtk ] || [ -e /usr/bin/jockey-kde ]; then
	JOCKEYSTAT="Installed"
else
	JOCKEYSTAT="Not Installed"
fi
# Essential Software Status
if [ -e /usr/bin/beesu ] && [ -e /usr/bin/cabextract ] && [ -e /usr/bin/dconf-editor ] && [ -d /usr/share/doc/p7zip-plugins* ] && [ -e /usr/bin/wget ] && [ -e /usr/bin/lzma ] && [ -e /usr/bin/unrar ] && [ -e /usr/lib/yum-plugins/fastestmirror.py ] && [ -d /usr/share/doc/gnome-tweak-tool* ]; then
	SOFTSTAT="Installed"
else
	SOFTSTAT="Not Installed"
fi
# Update
UPDATESTAT="Unknown"
echo -e $GREEN"Applications Info Loaded"$ENDCOLOR
}

function TweaksTasks()
{
DetectStatus
opt=$(zenity --list --width=600 --height=650 --title="$PROGRAM - Tweaks & Tasks" --checklist  --column "Select" --column "Options" --column "Status" TRUE "Set Yum to Keep Package Cache" "$YUMSTAT" TRUE "Install Tidy Cache Plugin" "$TIDYCACHESTAT" FALSE "Enable Autologin" "$AUTOLOGINSTAT" TRUE "Add Additional Repos" "$REPOSTAT" TRUE "Enable Touchpad Click" "$TOUCHPADSTAT" TRUE "Install Multimedia Codecs" "$CODECSTAT" FALSE "Enable DVD Playback" "$DVDSTAT" TRUE "Install Adobe Flash Plugin" "$FLASHSTAT" FALSE "Install Java Runtime Environment" "$JAVASTAT" FALSE "Install Wine with Gecko" "$GECKOSTAT" FALSE "Install GTalk Plugin" "$GTALKSTAT" TRUE "Add Colors to Terminal" "$COLORSTAT" FALSE "Add Fortune Messages to Terminal" "$FORTUNESTAT" TRUE "Set SELinux in Permissive Mode" "$SESTAT" FALSE "Install Microsoft Truetype Fonts" "$FONTSTAT" FALSE "Install Jockey Driver Installer" "$JOCKEYSTAT" TRUE "Install Essential Softwares" "$SOFTSTAT" TRUE "Update System" "$UPDATESTAT" --separator=":")
if [ $? == 1 ]; then
	Main
fi
arr=$(echo $opt | tr "\:" "\n")
for x in $arr
do
	if [ $x = "Yum" ]; then
	YumConfig
	fi
	if [ $x = "Tidy" ]; then
	TidyCache
	fi
	if [ $x = "Autologin" ]; then
	AutoLogin
	fi
	if [ $x = "Repos" ]; then
	AddRepo
	fi
	if [ $x = "Touchpad" ]; then
	TouchPad
	fi
	if [ $x = "Codecs" ]; then
	InstallCodecs
	fi
	if [ $x = "DVD" ]; then
	EnableDVD
	fi
	if [ $x = "Flash" ]; then
	InstallFlash
	fi
	if [ $x = "Java" ]; then
	InstallJava
	fi
	if [ $x = "Wine" ]; then
	WineGecko
	fi
	if [ $x = "GTalk" ]; then
	GTalk
	fi
	if [ $x = "Colors" ]; then
	ColorTerm
	fi
	if [ $x = "Fortune" ]; then
	FortuneTerm
	fi
	if [ $x = "SELinux" ]; then
	SELinuxConf
	fi
	if [ $x = "Fonts" ]; then
	CoreFonts
	fi
	if [ $x = "Jockey" ]; then
	InstallJockey
	fi
	if [ $x = "Essential" ]; then
	EssentialSoft
	fi
	if [ $x = "Update" ]; then
	SysUpdate
	fi
done
Done
Main
}

function Main()
{
main=$(zenity --list --width=300 --height=400 --title="$PROGRAM $VERSION" --text="Welcome to $PROGRAM $VERSION. Please choose an option" --radiolist  --column "Select" --column "Options" TRUE "Essential Tweaks & Tasks" FALSE "Fix Common Problems" FALSE "Optimize Boot Process" FALSE "Clean Up Options" FALSE "Install Shell Extensions" FALSE "Install Additional Software" FALSE "View System Information" FALSE "View Help" FALSE "Exit Program")
if [ $? == 1 ]; then
Terminate
fi
arr=$(echo $main | tr "\:" "\n")
for x in $arr
do
	if [ $x = "Tasks" ]; then
	TweaksTasks
	fi
	if [ $x = "Problems" ]; then
	FixProblems
	fi
	if [ $x = "Boot" ]; then
	OptimizeBoot
	fi
	if [ $x = "Clean" ]; then
	CleanUp
	fi
	if [ $x = "Shell" ]; then
	ShellExtensions
	fi
	if [ $x = "Software" ]; then
	InstallSoft
	fi
	if [ $x = "System" ]; then
	SysInfo
	fi
	if [ $x = "Help" ]; then
	Help
	fi
	if [ $x = "Exit" ]; then
	Complete
	fi
done
}

# Additional Parameters
trap Terminate INT

# Run the Program
CheckLock
CheckArgs
ShowLicense
EnableLog
CheckReq
Main
Complete

# Please report bugs at <http://fedorautils.sf.net>
# End of the Script
